package test.my.com.myapplicationtest.zhe_xian_tu_view.DynamicPathView.draw;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.util.AttributeSet;
import android.util.Log;
import android.view.TextureView;

import java.util.List;

import test.my.com.myapplicationtest.zhe_xian_tu_view.DynamicPathView.draw.DrawControl.BitmapControl;
import test.my.com.myapplicationtest.zhe_xian_tu_view.DynamicPathView.draw.DrawControl.CircleControl;
import test.my.com.myapplicationtest.zhe_xian_tu_view.DynamicPathView.draw.DrawControl.CirclePointControl;
import test.my.com.myapplicationtest.zhe_xian_tu_view.DynamicPathView.draw.DrawControl.DottedLineControl;
import test.my.com.myapplicationtest.zhe_xian_tu_view.DynamicPathView.draw.DrawControl.LineControl;
import test.my.com.myapplicationtest.zhe_xian_tu_view.DynamicPathView.draw.DrawControl.PathControl;
import test.my.com.myapplicationtest.zhe_xian_tu_view.DynamicPathView.draw.DrawControl.RectControl;
import test.my.com.myapplicationtest.zhe_xian_tu_view.DynamicPathView.draw.DrawControl.RoundRectTextControl;
import test.my.com.myapplicationtest.zhe_xian_tu_view.DynamicPathView.draw.DrawControl.TextControl;
import test.my.com.myapplicationtest.zhe_xian_tu_view.DynamicPathView.draw.model.BitmapModel;
import test.my.com.myapplicationtest.zhe_xian_tu_view.DynamicPathView.draw.model.CircleModel;
import test.my.com.myapplicationtest.zhe_xian_tu_view.DynamicPathView.draw.model.CirclePointModel;
import test.my.com.myapplicationtest.zhe_xian_tu_view.DynamicPathView.draw.model.DottedLineModel;
import test.my.com.myapplicationtest.zhe_xian_tu_view.DynamicPathView.draw.model.LineModel;
import test.my.com.myapplicationtest.zhe_xian_tu_view.DynamicPathView.draw.model.PathModel;
import test.my.com.myapplicationtest.zhe_xian_tu_view.DynamicPathView.draw.model.RectModel;
import test.my.com.myapplicationtest.zhe_xian_tu_view.DynamicPathView.draw.model.RoundRectTextModel;
import test.my.com.myapplicationtest.zhe_xian_tu_view.DynamicPathView.draw.model.TextModel;


/**
 * Created by qinghua on 2015/8/7.
 */
public class DrawView extends TextureView {

    public Canvas mCanvas;
    private Context mContext;
    // 默认白色背景
    private String backgroundColor = "#ffffff";

    public DrawView(Context context) {
        super(context);
        init(context);
    }

    public DrawView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public DrawView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context){
        this.mContext = context;
    }

    /**
     * 设置背景颜色
     * @param color
     */
    public void setBackgroundColor(String color){
        this.backgroundColor = color;
    }

    /**
     * 获取Canvas
     */
    public void getCanvas(){
        mCanvas = lockCanvas();
        if(mCanvas != null){
            mCanvas.drawColor(Color.parseColor(backgroundColor));
        }else{
            Log.e("ah","mCanvas == null");
        }
    }

    public void getNewCanvas() {
        mCanvas = lockCanvas();
        mCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
        mCanvas.drawColor(Color.parseColor(backgroundColor));
    }

    public void drawNewFinish() {
        unlockCanvasAndPost(mCanvas);
    }

    /**
     * 画完
     */
    public void drawFinish(){
        unlockCanvasAndPost(mCanvas);
    }

    public void drawLine(LineModel lineModel){
        LineControl lineControl = new LineControl(mCanvas,lineModel);
        lineControl.beginDraw();
    }

    public void drawText(TextModel textModel){
        TextControl textControl = new TextControl(mContext,mCanvas,textModel);
        textControl.beginDraw();
    }

    public void drawBitmaps(List<BitmapModel> bitmapModelList){
        BitmapControl bitmapControl = new BitmapControl(mCanvas,bitmapModelList);
        bitmapControl.beginDraw();
    }

    public void drawPath(PathModel pathModel){
        PathControl pathControl = new PathControl(mCanvas,pathModel);
        pathControl.beginDraw();
    }

    public void drawDottedLine(DottedLineModel dottedLineModel){
        DottedLineControl dottedLineControl = new DottedLineControl(mCanvas,dottedLineModel);
        dottedLineControl.beginDraw();
    }

    public void drawCirclePoints(List<CirclePointModel> circlePointModelList){
        CirclePointControl circlePointControl = new CirclePointControl(mCanvas,circlePointModelList);
        circlePointControl.beginDraw();
    }

    public void drawCirclePoint(CirclePointModel circlePointModel){
        CirclePointControl circlePointControl = new CirclePointControl(mCanvas,circlePointModel);
        circlePointControl.beginDraw();
    }

    public void drawRect(RectModel rectModel) {
        RectControl rectControl = new RectControl(mCanvas,rectModel);
        rectControl.beginDraw();
    }

    public void drawCircle(CircleModel circleModel) {
        CircleControl circleControl = new CircleControl(mCanvas,circleModel);
        circleControl.beginDraw();
    }

    public void drawRoundRectText(RoundRectTextModel roundRectTextModel) {
        RoundRectTextControl roundRectTextControl = new RoundRectTextControl(mCanvas, roundRectTextModel);
        roundRectTextControl.beginDraw();
    }

}
